//
// service.h
// libprotea
// Tools Library for the Protea Project / Service/Daemon functionality
// Copyright (C) 2003, 2004, 2005 eXegeSys, Inc.
// Copyright (C) 2008 Bruce A. James
//
// This program is part of the Protea Project.
//
// The Protea Project is free software; you can redistribute it and/or modify it 
// under the terms of the GNU General Public License as published by the 
// Free Software Foundation, either version 3 of the License, or (at your 
// option) any later version.
//
// The Protea Project is distributed in the hope that it will be useful, but 
// WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 
// for more details.
// 
// You should have received a copy of the GNU General Public License along 
// with this program.  If not, see <http://www.gnu.org/licenses/>.
// 
// Please send correspondence to:
// 
// theproteaproject@gmail.com
//

#ifndef __PROTEA_SERVICE_H__
#define __PROTEA_SERVICE_H__

// Forward declaration
class XCServiceDispatcher;

class __EXPORT XCService {
	friend class XCServiceDispatcher;

public:
	XCService( char* sName, char* DispName, char* Description, void* ctrlfunc, char* Dependencies );

	bool Install();
	bool Uninstall();

	virtual void OnInit() = 0;
	virtual	void OnRun() = 0;
	virtual void OnCleanup() = 0;
	virtual void OnSignalStop() = 0;

	// Add OS-Dependent Functions
	OSDEP_SERVICE_FUNCTIONS

	XCService* next;
	char* name;
	char* dispname;
	char* description;
	char* dependencies;

	OSDEP_SERVICE_MAIN main;

protected:
	void Run( bool as_service );
};



class __EXPORT XCServiceDispatcher {
public:
	XCServiceDispatcher() { count = 0; };
	~XCServiceDispatcher();

	void Add( XCService* service );
	bool Register();

	// Add OS-Dependent Functions
	OSDEP_SERVICE_DISPATCH_FUNCTIONS

	void SetService( bool new_state );

	bool StartRemoteService( const char* machine, const char* name );

protected:
	static bool service_state;

	static XCService* service_list;
	long count;
};

#endif
